# 在你的Django应用的templatetags目录下创建一个python模块，例如calc.py
from django import template
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter(name='sub')
def sub(value, arg):
    value1 = int(float(value))
    try:
        return value1 - arg
    except TypeError:
        return value


@register.filter(name='plus')
def plus(value, arg):
    value1 = int(float(value))
    try:
        return value1 + arg
    except TypeError:
        return value
